package inputFrames;

import java.awt.*;

import javax.swing.*;

import constants.*;

import person.*;

public class PersonInputPanel extends JPanel {
    private JTextField nameTextField;
    private ButtonGroup buttonGroup;
    private GridBagLayout gridBagLayout;
    private JLabel nameLabel, sexLabel, ageLabel;
    private JRadioButton maleButton, femaleButton;
    private JSpinner ageSpinner;
    private JLabel label;

    public PersonInputPanel() {
	this.setLayout(null);
	this.setBackground(Constants.PANEL_BACKGROUND_COLOR);
	this.setSize(Constants.INPUT_PANEL_SIZE_WIDTH, Constants.INPUT_PANEL_SIZE_HEIGHT);

	// name components
	nameLabel = new JLabel("Name : ");
	nameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
	nameLabel.setBounds(50, 50, 50, 50);
	this.add(nameLabel);

	nameTextField = new JTextField();
	nameTextField.setColumns(20);
	nameTextField.setBounds(100, 65, 100, 20);
	this.add(nameTextField);

	// sex components
	buttonGroup = new ButtonGroup();

	sexLabel = new JLabel("Sex : ");
	sexLabel.setHorizontalAlignment(SwingConstants.RIGHT);
	sexLabel.setBounds(50, 100, 50, 50);
	this.add(sexLabel);

	maleButton = new JRadioButton("Male");
	maleButton.setBackground(Constants.PANEL_BACKGROUND_COLOR);
	maleButton.setBounds(100, 100, 55, 50);
	maleButton.setSelected(true);
	buttonGroup.add(maleButton);
	this.add(maleButton);

	femaleButton = new JRadioButton("Female");
	femaleButton.setBackground(Constants.PANEL_BACKGROUND_COLOR);
	femaleButton.setBounds(155, 100, 75, 50);
	buttonGroup.add(femaleButton);
	this.add(femaleButton);

	// age components
	ageLabel = new JLabel("Age : ");
	ageLabel.setHorizontalAlignment(SwingConstants.RIGHT);
	ageLabel.setBounds(50, 150, 50, 50);
	this.add(ageLabel);

	ageSpinner = new JSpinner();
	ageSpinner.setModel(new SpinnerNumberModel(20, 0, 120, 1));
	ageSpinner.setBounds(100, 163, 50, 25);
	this.add(ageSpinner);

    }
    
    @Override
    public void paint(Graphics g) {
        // TODO Auto-generated method stub
        super.paint(g);
        
        g.drawImage(Constants.INPUT_IMG, 3, 15, this);
    }

    public void inputInfo(Person person) {
	person.setName(nameTextField.getText());

	if (maleButton.isSelected()) {
	    person.setSex(constants.Constants.SEX_TYPE.MALE);
	} else if (femaleButton.isSelected()) {
	    person.setSex(constants.Constants.SEX_TYPE.FEMALE);
	}

	person.setAge((int) ageSpinner.getValue());

    }
}
